package org.example.service.impl;

import org.example.Mapper.ActivityMapper;
import org.example.Mapper.SummaryMapper;
import org.example.Mapper.UserMapper;
import org.example.domain.Activity;
import org.example.domain.Summary;
import org.example.domain.User;
import org.example.service.SummaryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class SummaryServiceImpl implements SummaryService {

    @Autowired
    private SummaryMapper summaryMapper;

    @Autowired
    private ActivityMapper activityMapper;

    @Autowired
    private UserMapper userMapper;

    @Override
    public void addOneSummary(Summary summary) {
        summaryMapper.addOneSummary(summary.getUserId(),summary.getActivityId(),summary.getContent());
    }

    @Override
    public Summary[] getSummariesByUserId(Integer userId,Integer start) {
        Summary[] summaries=summaryMapper.getSummariesByUserId(userId,start);
        for (Summary summary : summaries) {
            Activity activity=activityMapper.getAllById(summary.getActivityId());
            summary.setActivity(activity);
        }
        return summaries;
    }

    @Override
    public Summary[] getSummariesByActivityId(Integer activityId, Integer start) {
        Summary[] summaries=summaryMapper.getSummariesByActivityId(activityId,start);
        for (Summary summary : summaries) {
            User user=userMapper.getAllById(summary.getUserId());
            summary.setUser(user);
        }
        return summaries;
    }

    @Override
    public void changeStatusById(Integer id) {
        summaryMapper.changeStatusById(id);
    }
}
